<template>
  <home-content title="活跃用户">
    <el-tabs v-model="activeName" @tab-click="clickHandle">
      <el-tab-pane class="tabs_item" label="日活跃用户" name="day">
        <chart-area
          v-if="liveData.dayLiveList.length > 0 && activeName == 'day'"
          :x-data="liveData.dayList"
          :chart-data="liveData.dayLiveList"
          :timepicker="true"
          :toolbox="true"
          @reset-time="resetTime"
          tipName="dau"
        ></chart-area>
      </el-tab-pane>
      <el-tab-pane class="tabs_item" label="周活跃用户" name="week">
        <chart-area
          v-if="activeName == 'week'"
          :x-data="liveData.dayList"
          :chart-data="liveData.weekLiveList"
          :timepicker="true"
          :toolbox="true"
          @reset-time="resetTime"
          tipName="wau"
        ></chart-area>
      </el-tab-pane>
      <el-tab-pane class="tabs_item" label="月活跃用户" name="month">
        <chart-area
          v-if="activeName == 'month'"
          :x-data="liveData.dayList"
          :chart-data="liveData.monthLiveList"
          :timepicker="true"
          :toolbox="true"
          @reset-time="resetTime"
          tipName="mau"
        ></chart-area>
      </el-tab-pane>
    </el-tabs>
    <div class="table_container">
      <el-row justify="center">
        <el-col :span="6">时间</el-col>
        <el-col :span="6">DAU(日活跃用户数)</el-col>
        <el-col :span="6">WAU(周活跃用户数)</el-col>
        <el-col :span="6">MAU(月活跃用户数)</el-col>
      </el-row>
      <el-row v-for="(item,index) in liveDataResponse" :key="index">
        <el-col class="table-item" :span="6">{{ item.day }}</el-col>
        <el-col class="table-item" :span="6">{{ item.dau }}</el-col>
        <el-col class="table-item" :span="6">{{ item.wau }}</el-col>
        <el-col class="table-item" :span="6">{{ item.mau }}</el-col>
      </el-row>
    </div>
  </home-content>
</template>

<script>
import HomeContent from "@/components/HomeContent.vue";
import ChartArea from "@/components/ChartArea.vue";
import request from "@/utils/request";
import dayjs from "dayjs";
import { getLiveList } from "@/utils/getChartsData";
export default {
  name: "Lively",
  components: {
    "home-content": HomeContent,
    "chart-area": ChartArea
  },
  data() {
    return {
      activeName: "day",
      liveData: {
        dayLiveList: [],
        weekLiveList: [],
        monthLiveList: [],
        dayList: []
      },
      liveDataResponse: [],
      startDate: null,
      endDate: null
    };
  },
  created() {
    this.startDate = dayjs()
      .subtract(10, "day")
      .format("YYYY-MM-DD");
    this.endDate = dayjs().format("YYYY-MM-DD");
    this.initLiveData();
  },
  methods: {
    clickHandle() {},
    async initLiveData() {
      const result = await getLiveList({
        startDate: this.startDate,
        endDate: this.endDate
      });
      console.log(result)
      this.liveDataResponse = result.responseList;
      this.liveData.dayLiveList = result.dayLiveList;
      this.liveData.weekLiveList = result.weekLiveList;
      this.liveData.monthLiveList = result.monthLiveList;
      this.liveData.dayList = result.xlist;
    },
    resetTime(date) {
      this.startDate = dayjs(date[0]).format("YYYY-MM-DD");
      this.endDate = dayjs(date[1]).format("YYYY-MM-DD");
      this.initLiveData();
    }
  }
};
</script>

<style lang="less" scoped>
.el-row {
  border-top: 1px solid #eee;
}
.el-col {
  text-align: center;
  background-color: #f2f2f2;
  line-height: 58px;
  font-size: 16px;
  color: #666666ff;
  border-right: 1px solid #e0e0e0;
  &:nth-child(4) {
    border-right: 0;
  }
}
.table-item {
  font-size: 14px;
  background-color: #fff;
}
</style>